package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.JcMyPriceListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class JcMyPirceAdapter extends BaseRecycleAdapter<JcMyPriceListEntity> {

    private DeleteListerner deleteListener;
    private TextView tvTwoType;
    private TextView tvQuotationType;
    private TextView tvJoinType;

    public JcMyPirceAdapter(Context context, List<JcMyPriceListEntity> datas) {
        super(context, R.layout.item_jc_my_price, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, JcMyPriceListEntity goodsInfoEntity3) {
        holder.setBinding(BR.viewModel, goodsInfoEntity3);
        TextView tvGroupBuyType = holder.getItem().findViewById(R.id.tv_group_buy_type);
        tvTwoType = holder.getItem().findViewById(R.id.tv_two_type);
        tvQuotationType = holder.getItem().findViewById(R.id.tv_quotation_type);
        tvJoinType = holder.getItem().findViewById(R.id.tv_join_type);
        TextView tvReprice = holder.itemView.findViewById(R.id.tv_reprice);//再次报价
        TextView tvExit = holder.itemView.findViewById(R.id.tv_exit);//退出
        TextView tvDelete = holder.itemView.findViewById(R.id.tv_delete);//删除
        ImageView ivStatus = holder.itemView.findViewById(R.id.iv_status);

        switch (goodsInfoEntity3.getGroupbuyType()) {//1即报集采 2 汇总集采
            case "1":
                tvGroupBuyType.setBackgroundResource(R.mipmap.jbjc);
                tvGroupBuyType.setText("即报即采");
                break;
            case "2":
                tvGroupBuyType.setBackgroundResource(R.mipmap.hzcg);
                tvGroupBuyType.setText("汇集采购");
                break;
            case "3":
                tvGroupBuyType.setBackgroundResource(R.mipmap.qyzx);
                tvGroupBuyType.setText("企业专项");
                break;
        }
        switch (goodsInfoEntity3.getGroupbuyClass()) { //第二类型标签     //报价类型: 1：商品材料   2：机械租赁  3：设备租赁
            case "1":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("商品材料");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            case "2":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("机械租赁");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            case "3":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("设备租赁");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            default:
                tvTwoType.setVisibility(View.GONE);
                break;
        }
        switch (goodsInfoEntity3.getOfferType()) {//报价类型: 2：市场报价   1：会员报价
            case "1":
                tvQuotationType.setVisibility(View.VISIBLE);
                tvQuotationType.setText("客户报价");
                tvQuotationType.setTextColor(context.getResources().getColor(R.color.color_FDA72D));
                tvQuotationType.setBackgroundResource(R.drawable.bg_market_join_price);
                break;
            case "2":
                tvQuotationType.setVisibility(View.VISIBLE);
                tvQuotationType.setTextColor(context.getResources().getColor(R.color.color_0286DF));
                tvQuotationType.setText("市场报价");
                tvQuotationType.setBackgroundResource(R.drawable.bg_marketprice);
                break;
            case "3":
                tvQuotationType.setVisibility(View.VISIBLE);
                tvQuotationType.setTextColor(context.getResources().getColor(R.color.color_FF4B10));
                tvQuotationType.setText("成员报价");
                tvQuotationType.setBackgroundResource(R.drawable.bg_memberoffer);
                break;
            default:
                tvQuotationType.setVisibility(View.GONE);
                break;
        }
        //加盟客户类型
        switch (goodsInfoEntity3.getJoinType()) {//1、市场加盟 2、会员加盟 3、成员加盟
            case "1":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_FDA72D));
                tvJoinType.setText("客户加盟");
                tvJoinType.setBackgroundResource(R.drawable.bg_market_join_price);

                break;
            case "2":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setText("市场加盟");
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_0286DF));
                tvJoinType.setBackgroundResource(R.drawable.bg_marketprice);
                break;
            case "3":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_FF4B10));
                tvJoinType.setText("成员加盟");
                tvJoinType.setBackgroundResource(R.drawable.bg_memberoffer);
                break;
            default:
                tvJoinType.setVisibility(View.GONE);
                break;
        }
        if (goodsInfoEntity3.getStatus().equals("2")){
            tvExit.setVisibility(View.GONE);
            tvReprice.setVisibility(View.GONE);
            tvDelete.setVisibility(View.VISIBLE);
            ivStatus.setImageResource(R.mipmap.collect_complate);
        }else {
            tvExit.setVisibility(View.VISIBLE);
            tvReprice.setVisibility(View.VISIBLE);
            tvDelete.setVisibility(View.GONE);
            ivStatus.setImageResource(R.mipmap.collect_ing);
        }

        //我的报价-退出
        tvExit.setOnClickListener(view -> {
            if (null != deleteListener) {
                deleteListener.exit(goodsInfoEntity3);
            }
        });
        //我的报价-修改报价
        tvReprice.setOnClickListener(view -> {
            if (null != deleteListener) {
                deleteListener.priceDetail(goodsInfoEntity3);
            }
        });
        //我的报价-删除
        tvDelete.setOnClickListener(view -> {
            if (null != deleteListener) {
                deleteListener.delete(goodsInfoEntity3);
            }
        });
    }

    public interface DeleteListerner {
        void delete(JcMyPriceListEntity entity);

        void exit(JcMyPriceListEntity entity);

        void priceDetail(JcMyPriceListEntity entity);
    }

    public void setDeleteListener(DeleteListerner listener) {
        this.deleteListener = listener;
    }

}
